Skip to content

Add dispatch-dev for isolated agent dev environments#45

Merged
selfcontained merged 6 commits into
mainfrom
feat/dispatch-dev
Mar 13, 2026
Merged

Add dispatch-dev for isolated agent dev environments#45
selfcontained merged 6 commits into
mainfrom
feat/dispatch-dev

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

Summary

  • dispatch-dev CLI tool that agents use instead of npm run dev — bootstraps an isolated Postgres container, API server, and optional Vite frontend in sibling tmux windows within the agent's session
  • All services auto-cleanup when the agent is stopped or deleted (tmux windows die with the session, Docker containers cleaned up by AgentManager.cleanupDevEnvironment)
  • Zero-config for agents: dispatch-dev up picks free ports, loads .env, prints URLs
  • Fixes agents killing themselves when restarting dev servers (the root cause of agents dying unexpectedly)

Changes

  • bin/dispatch-dev — new CLI with up/down/restart/status/logs/url commands
  • src/agents/manager.tscleanupDevEnvironment() removes Docker containers + state files on stop/delete
  • docker-compose.yml — ephemeral volumes (no shared pgdata across agent containers)
  • CLAUDE.md + AGENTS.md — consolidated dev server/DB docs around dispatch-dev, removed manual npm run dev and worktree DB instructions
  • scripts/e2e-isolated.sh + playwright.config.ts — isolated e2e test runner with TLS support

Test plan

  • dispatch-dev up creates Docker DB + API tmux window, both healthy
  • dispatch-dev up --vite creates all three services (DB + API + Vite)
  • dispatch-dev status reports all services correctly
  • dispatch-dev down tears down tmux windows, Docker container, and state file
  • dispatch-dev restart replaces windows without accumulating extras
  • Killing agent tmux session kills dev server process (lifecycle tie)
  • cleanupDevEnvironment path: reads state file, removes container
  • npm run check passes
  • npm test passes (25/25)

🤖 Generated with Claude Code

selfcontained and others added 6 commits March 12, 2026 16:26
Agents running `npm run dev` directly could kill their own process
when restarting dev servers (the tmux session and agent CLI share a
process tree). dispatch-dev runs DB, API, and Vite in sibling tmux
windows tied to the agent session — automatic lifecycle cleanup on
agent stop/delete, no orphaned servers, no port conflicts.

- bin/dispatch-dev: bootstraps isolated Postgres container + API +
  optional Vite, all auto-assigned ports, zero-config for agents
- AgentManager.cleanupDevEnvironment: removes Docker containers and
  state files on agent stop/delete
- docker-compose.yml: ephemeral volumes per container (no shared pgdata)
- CLAUDE.md/AGENTS.md: consolidated dev docs around dispatch-dev
- scripts/e2e-isolated.sh + playwright TLS/isolated support

Co-Authored-By: Claude Opus 4.6 <[email protected]>
npm run test:e2e now always spins up its own Postgres container and
API server on random ports via e2e-isolated.sh. No more reuseExistingServer
which could cause agents to accidentally share dev servers.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- e2e-isolated.sh: use node net module to grab free ports from the OS
  instead of $RANDOM, preventing collisions between concurrent runs
- cleanupDevEnvironment: fire-and-forget with 10s timeout on docker rm
  so it can't block agent stop/delete API calls

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Fix floating promise: add .catch() to fire-and-forget
  cleanupDevEnvironment calls so errors are logged not swallowed
- Add docker compose project name (-p) to dispatch-dev for consistent
  container namespacing
- Use PID+timestamp for e2e run IDs to avoid CI parallel collisions
- Add TOCTOU comments to find_free_port in both scripts
- Add comment explaining NODE_TLS_REJECT_UNAUTHORIZED scope
- Rename DEV_DB_NAME to DEV_CONTAINER_SUFFIX for clarity
- Document start/stop aliases in dispatch-dev usage
- Remove unrelated .dispatch/config.json change

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Session names now follow the pattern dispatch_agt_xxx_task-slug
(e.g. dispatch_agt_393f6be6672e_projects) instead of just
dispatch_agt_393f6be6672e. Makes it easy to identify agents when
debugging rogue tmux sessions with tmux list-sessions.

Added agentIdFromSessionName() helper to reliably extract the agent
ID from either the old or new session name format.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
dispatch-dev now finds the agent's tmux session by prefix match
instead of exact match, since session names now include the agent
name slug (e.g. dispatch_agt_xxx_my-task).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@selfcontained
selfcontained merged commit 672d90c into main Mar 13, 2026
1 check passed
@selfcontained
selfcontained deleted the feat/dispatch-dev branch March 13, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant